<?php

    //1.引入文件，连接数据库
    require_once ('common/conn.php');

    // 2. 查询文章分类
    $sql1 = "select * from category where is_show=1 order by id desc";
    $result1 = mysqli_query($link, $sql1);
    if($result1 === false){
        mysqli_close($link);
        exit('查询失败');
    }
    $rows1 = mysqli_fetch_all($result1,MYSQLI_ASSOC);

    // 4. 查询文章总数
    $sql3 = "select count(*) from article";
    $result3 = mysqli_query($link, $sql3);
    $row3 = mysqli_fetch_array($result3);


    // 5. 查询文章分类总数
    $sql4 = "select count(*) from category";
    $result4 = mysqli_query($link, $sql4);
    $row4 = mysqli_fetch_array($result4);

    //6.关闭连接
    mysqli_close($link);

?>

<div class="col-md-3 sidebar">
    <div class="clearfix"></div>
    <div class="sidebar-content">
        <!-- start search area -->
        <form class="form-horizontal" role="form" action="index.php" method="GET">
            <input id="search" class="form-control" name="keyword" type="search" placeholder="美食" value="">
            <button type="submit" name="submit" class="animation red-btn">Search</button>
        </form>

        <!-- start bootstrap.cssinfo area -->
        <div class="card">
            <div class="header"></div>
            <div class="avater">
                <img alt="avater" src="img/dog.jpg">
            </div>
            <div class="content">
                <h3>Roem</h3>
                <ul class="status">
                    <li><span class="normal"><?=$row3[0]?></span><br>文章</li>
                    <li><span class="normal"><?=$row4[0]?></span><br>分类</li>
                </ul>
            </div>
            <div style="clear:both;"></div>
        </div>

        <!-- start category area -->
        <h5>分类</h5>
        <ul class="nav nav-sidebar">
            <li class="">
                <a href="index.php?name=全部文章" class="no-barba-prefetch">全部文章</a>
            </li>
            <li class="">
                <a href="index.php?name=按点击率" class="no-barba-prefetch">按点击率</a>
            </li>
            <?php foreach($rows1 as $value):?>
                <li class="">
                    <a href="index.php?name=<?=$value['name']?>" class="no-barba-prefetch">
                        <?=$value['name']?><sup></sup>
                    </a>
                </li>
            <?php endforeach; ?>
        </ul>

    </div>

</div>